using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace GuavaData
{
    public class DataGridViewNumberBoxCell : DataGridViewTextBoxCell
    {
        GuavaData.Domain.GNumericDomains dom;
        
        public GuavaData.Domain.GNumericDomains Dom
        {
            get { return dom; }
            set { dom = value; }
        }
        
        public DataGridViewNumberBoxCell()
            : base()
        {
            dom = GuavaData.Domain.GNumericDomains.Integer1Byte;
        }

        //protected override void OnDataGridViewChanged()
        //{
        //    base.OnDataGridViewChanged();
        //    if (this.DataGridView != null) this.DataGridView.DataError += new DataGridViewDataErrorEventHandler(DataGridView_DataError);
        //}

        //void DataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
        //{
        //    if (e.Exception == null) return;
        //    MessageBox.Show(e.Context.ToString());
        //    e.ThrowException = false;
        //}

        public override Type ValueType
        {
            get
            {
                switch (dom)
                {
                    case GuavaData.Domain.GNumericDomains.Integer1Byte:
                        return typeof(byte);
                    case GuavaData.Domain.GNumericDomains.Integer2Byte:
                        return typeof(short);
                    case GuavaData.Domain.GNumericDomains.Integer4Byte:
                        return typeof(int);
                    case GuavaData.Domain.GNumericDomains.Integer8Byte:
                        return typeof(long);
                    case GuavaData.Domain.GNumericDomains.FixedPoint:
                        return typeof(decimal);
                    case GuavaData.Domain.GNumericDomains.FloatingPointSingle:
                        return typeof(float);
                    case GuavaData.Domain.GNumericDomains.FloatingPointDouble:
                        return typeof(double);
                }
                return base.ValueType;
            }
        }
    }
}
